
package view;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import model.PersonLid;

/**
 *
 * @author 12016977 GEORGIOS FLOURIS
 */
public class LedenBeheer extends javax.swing.JFrame {
    private boolean validationPassed= true;
    PersonLid thisMember = new PersonLid();
  
     
    public LedenBeheer() {
        initComponents();
        
        // Show provisional code on the non editable jTextField from code
        codeField.setText(Integer.toString((PersonLid.getNextCode())));
        // Show provisional date (current date)
        startLidmaatschapField.setText(thisMember.getCurrentDate());
        // Show provisional end date
        eindLidmaatschapField.setText(thisMember.getCurrentDatePlusYear());
        setDefaultCloseOperation(LedenBeheer.DISPOSE_ON_CLOSE);
                
    }
    
    // constructor with attribute. To be used by the search functionality to insert data.
    public LedenBeheer(PersonLid selectedLidForUpdate) {
        initComponents();
        dataToUpdate(selectedLidForUpdate);
    }
    
    // Put the data of the member to be changed on the Gui
    private void dataToUpdate(PersonLid selectedLidForUpdate) {
    
        thisMember = selectedLidForUpdate;
        //show existing code in the screen for the PersonLid to be updated (diff when new member is entered)
        codeField.setText(Integer.toString(thisMember.getCode()));
        naamField.setText(thisMember.getNaam());
        straatField.setText(thisMember.getStraat());
        huisnummerField.setText(thisMember.getHuisnummer());
        postcodeField.setText(thisMember.getPostcode());
        geslachtCombo.setSelectedItem(thisMember.getGeslacht());
        emailField.setText(thisMember.getEmail());
        telefoonField.setText(thisMember.getTelefoon());
        plaatsField.setText(thisMember.getPlaats());
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String dateStringStartDate = dateFormat.format(thisMember.getStartLidmaatschap());
        startLidmaatschapField.setText(dateStringStartDate);
        String dateStringEindDate = dateFormat.format(thisMember.getEindLidmaatschap());
        eindLidmaatschapField.setText(dateStringEindDate);
       
    }
    
    /**
     * This method is called from within the constructor to init the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        naamField = new javax.swing.JTextField();
        naamLabel = new javax.swing.JLabel();
        zoekButton = new javax.swing.JButton();
        codeField = new javax.swing.JTextField();
        codeLabel = new javax.swing.JLabel();
        straatField = new javax.swing.JTextField();
        straatLabel = new javax.swing.JLabel();
        lidToevoegenButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        postcodeField = new javax.swing.JTextField();
        postcodeLabel = new javax.swing.JLabel();
        huisnummerField = new javax.swing.JTextField();
        huisnummerLabel = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        kindButton = new javax.swing.JButton();
        kindToeveogenLabel = new javax.swing.JLabel();
        geslachtCombo = new javax.swing.JComboBox();
        geslachtLabel = new javax.swing.JLabel();
        emailField = new javax.swing.JTextField();
        emailLabel = new javax.swing.JLabel();
        telefoonField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        plaatsField = new javax.swing.JTextField();
        plaatsLabel = new javax.swing.JLabel();
        startLidmaatschapField = new javax.swing.JTextField();
        startLidmaatschapLabel = new javax.swing.JLabel();
        ledenReportButton = new javax.swing.JButton();
        eindLidmaatschapField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        annulerenButton = new javax.swing.JButton();
        errorHuisnummerField = new javax.swing.JLabel();
        errorNaamField = new javax.swing.JLabel();
        errorStraatField = new javax.swing.JLabel();
        errorPostcodeField = new javax.swing.JLabel();
        errorGeslachtField = new javax.swing.JLabel();
        errorEmailField = new javax.swing.JLabel();
        errorTelefoonField = new javax.swing.JLabel();
        errorPlaatsField = new javax.swing.JLabel();
        errorStartdatumField = new javax.swing.JLabel();
        errorEinddatumField = new javax.swing.JLabel();
        sluitenButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Leden Beheer");
        setIconImages(null);

        naamField.setToolTipText("Letters: 'A' tot 'Z'");
        naamField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                naamFieldActionPerformed(evt);
            }
        });

        naamLabel.setText("Naam*");
        naamLabel.setToolTipText("bv Georgios Sokrates Flouris");

        zoekButton.setText("Lid Zoeken");
        zoekButton.setToolTipText("zoek leden in DB");
        zoekButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zoekButtonActionPerformed(evt);
            }
        });

        codeField.setEditable(false);
        codeField.setBackground(new java.awt.Color(204, 204, 204));
        codeField.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        codeField.setToolTipText("Automatisch gegenereerd");
        codeField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                codeFieldActionPerformed(evt);
            }
        });

        codeLabel.setText("Lidnummer");

        straatField.setToolTipText("Letters: 'A' tot 'Z'");
        straatField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                straatFieldActionPerformed(evt);
            }
        });

        straatLabel.setText("Straat*");
        straatLabel.setToolTipText("bv Athenekleinstraat");

        lidToevoegenButton.setText("Opslaan");
        lidToevoegenButton.setToolTipText("Lid gegevens in DB invoeren");
        lidToevoegenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lidToevoegenButtonActionPerformed(evt);
            }
        });

        postcodeField.setToolTipText("4 cijfers en 2 Letters");
        postcodeField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                postcodeFieldActionPerformed(evt);
            }
        });

        postcodeLabel.setText("Postcode*");
        postcodeLabel.setToolTipText("bv 2356AC");

        huisnummerField.setToolTipText("Cijfers en Letters");

        huisnummerLabel.setText("Huisnummer*");
        huisnummerLabel.setToolTipText("bv 134B");

        kindButton.setText("Kinderen");
        kindButton.setToolTipText("kind gegevens voor dit lid");
        kindButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                kindButtonActionPerformed(evt);
            }
        });

        kindToeveogenLabel.setText("Kinderen toevoegen");

        geslachtCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "kies", "M", "V" }));
        geslachtCombo.setToolTipText("M = man, V = vrouw");

        geslachtLabel.setText("Geslacht*");
        geslachtLabel.setToolTipText("M = man, V = vrouw");

        emailField.setToolTipText("moet een geldig eMail adress zijn");

        emailLabel.setText("email");
        emailLabel.setToolTipText("bv geo.flouris@gmail.com");

        telefoonField.setToolTipText(" alleen cijfers");

        jLabel1.setText("telefoon");
        jLabel1.setToolTipText("bv 023 555555555");

        plaatsField.setToolTipText("plaats naam");

        plaatsLabel.setText("plaats");
        plaatsLabel.setToolTipText("bv Hoofddorp");

        startLidmaatschapField.setToolTipText("datum moet in de vorm: 'CCYY-MM-DD' zijn");
        startLidmaatschapField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startLidmaatschapFieldActionPerformed(evt);
            }
        });

        startLidmaatschapLabel.setText("Start Lidmaatschap*");
        startLidmaatschapLabel.setToolTipText("bv 2013-01-01");

        ledenReportButton.setText("Leden Overzicht");
        ledenReportButton.setToolTipText("naar Leden overzicht");
        ledenReportButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ledenReportButtonActionPerformed(evt);
            }
        });

        eindLidmaatschapField.setToolTipText("datum moet in de vorm: 'CCYY-MM-DD' zijn");

        jLabel2.setText("Eind Lidmaatschap*");
        jLabel2.setToolTipText("bv 2013-01-01");

        annulerenButton.setText("Annuleren");
        annulerenButton.setToolTipText("Reset alle velden");
        annulerenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                annulerenButtonActionPerformed(evt);
            }
        });

        errorHuisnummerField.setForeground(new java.awt.Color(204, 0, 0));

        errorNaamField.setForeground(new java.awt.Color(204, 51, 0));

        errorStraatField.setForeground(new java.awt.Color(204, 51, 0));

        errorPostcodeField.setForeground(new java.awt.Color(204, 51, 0));

        errorGeslachtField.setForeground(new java.awt.Color(204, 51, 0));

        errorEmailField.setForeground(new java.awt.Color(204, 51, 0));

        errorTelefoonField.setForeground(new java.awt.Color(204, 51, 0));

        errorPlaatsField.setForeground(new java.awt.Color(204, 51, 0));

        errorStartdatumField.setForeground(new java.awt.Color(204, 51, 0));

        errorEinddatumField.setForeground(new java.awt.Color(204, 51, 0));

        sluitenButton.setText("Sluiten");
        sluitenButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sluitenButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(22, 22, 22)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(ledenReportButton, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(54, 54, 54)
                                        .addComponent(zoekButton, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 1, Short.MAX_VALUE)
                                        .addComponent(jSeparator1)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(kindToeveogenLabel)
                                .addGap(57, 57, 57)))
                        .addComponent(kindButton, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(22, 22, 22)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(straatLabel)
                                    .addComponent(postcodeLabel)
                                    .addComponent(huisnummerLabel)
                                    .addComponent(naamLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(codeLabel)
                                    .addComponent(geslachtLabel)
                                    .addComponent(emailLabel)
                                    .addComponent(jLabel1)
                                    .addComponent(plaatsLabel)
                                    .addComponent(startLidmaatschapLabel)
                                    .addComponent(jLabel2))
                                .addGap(39, 39, 39))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(sluitenButton, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(huisnummerField, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                                    .addComponent(postcodeField, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                                    .addComponent(geslachtCombo, 0, 120, Short.MAX_VALUE)
                                    .addComponent(startLidmaatschapField, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                                    .addComponent(eindLidmaatschapField))
                                .addGap(173, 173, 173))
                            .addComponent(codeField)
                            .addComponent(naamField)
                            .addComponent(emailField)
                            .addComponent(telefoonField)
                            .addComponent(plaatsField, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(straatField, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(19, 19, 19)
                                .addComponent(annulerenButton, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lidToevoegenButton, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(errorHuisnummerField, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(errorEinddatumField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
                                .addComponent(errorStartdatumField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(errorPlaatsField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(errorTelefoonField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(errorEmailField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(errorGeslachtField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(errorPostcodeField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(errorNaamField, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(errorStraatField, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ledenReportButton)
                    .addComponent(zoekButton))
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(codeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(codeLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(naamField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(naamLabel)
                    .addComponent(errorNaamField))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(straatField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(straatLabel)
                    .addComponent(errorStraatField))
                .addGap(13, 13, 13)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(huisnummerField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(huisnummerLabel)
                    .addComponent(errorHuisnummerField))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(postcodeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(postcodeLabel)
                    .addComponent(errorPostcodeField))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(geslachtCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(geslachtLabel)
                    .addComponent(errorGeslachtField))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(emailField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(emailLabel)
                    .addComponent(errorEmailField))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(telefoonField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(errorTelefoonField))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(plaatsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(plaatsLabel)
                    .addComponent(errorPlaatsField))
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(startLidmaatschapField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(startLidmaatschapLabel)
                    .addComponent(errorStartdatumField))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(eindLidmaatschapField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(errorEinddatumField))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lidToevoegenButton)
                    .addComponent(annulerenButton)
                    .addComponent(sluitenButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(kindButton)
                    .addComponent(kindToeveogenLabel))
                .addGap(13, 13, 13))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void naamFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_naamFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_naamFieldActionPerformed

    private void zoekButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoekButtonActionPerformed
       new LidZoeken().setVisible(true);
       //Close window when user goes back to function
       this.dispose();
    }//GEN-LAST:event_zoekButtonActionPerformed

    private void codeFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_codeFieldActionPerformed
         
    }//GEN-LAST:event_codeFieldActionPerformed

    private void straatFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_straatFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_straatFieldActionPerformed

    private void lidToevoegenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lidToevoegenButtonActionPerformed
        
        /*
         * MULTIPLE TRY CATCH
         * 
         * INTENTION: is to give the user a unified message for all fields
         */
        
                // Clean all error codes.
                errorNaamField.setText("");
                errorStraatField.setText("");
                errorHuisnummerField.setText("");
                errorPostcodeField.setText("");
                errorGeslachtField.setText("");
                errorEmailField.setText("");
                errorTelefoonField.setText("");
                errorPlaatsField.setText("");
                errorStartdatumField.setText("");
                errorEinddatumField.setText("");
        
                validationPassed=true;           
                //CODE user has no access
                thisMember.setCode(Integer.valueOf(codeField.getText()));
              
                
                //NAAM
                try{
                    thisMember.setNaam(naamField.getText());
                    
                } catch (Exception ex) {
                    
                    validationPassed= false;           
                    errorNaamField.setText(ex.getMessage());  
                }
                
                //STRAAT
                try{
                   thisMember.setStraat(straatField.getText());
                    
                } catch (Exception ex) {
                    
                    validationPassed= false;        
                    errorStraatField.setText(ex.getMessage());  
                }
                
                //HUISNUMMER
                try{
                    thisMember.setHuisnummer(huisnummerField.getText());
                    
                } catch (Exception ex) {
                    
                    validationPassed= false;            
                    errorHuisnummerField.setText(ex.getMessage());  
                }
          
                //POSTCODE
                try{
                    thisMember.setPostcode(postcodeField.getText());
                    
                } catch (Exception ex) {
                    
                    validationPassed= false;           
                    errorPostcodeField.setText(ex.getMessage());  
                }
            
                //GESLACHT
                try{
                    thisMember.setGeslacht(String.valueOf(geslachtCombo.getSelectedItem()));
                    
                } catch (Exception ex) {
                    
                    validationPassed= false;           
                    errorGeslachtField.setText(ex.getMessage());  
                }
                
                //EMAIL
                try{
                    thisMember.setEmail(emailField.getText());
                    
                } catch (Exception ex) {
                    
                    validationPassed= false;            
                    errorEmailField.setText(ex.getMessage());  
                }
                
                //TELEFOON
                try{
                    thisMember.setTelefoon(telefoonField.getText());
                    
                } catch (Exception ex) {
                    
                    validationPassed= false;            
                    errorTelefoonField.setText(ex.getMessage());  
                }
                
                //PLAATS
                try{
                    thisMember.setPlaats(plaatsField.getText());
                    
                } catch (Exception ex) {
                    
                    validationPassed= false;             
                    errorPlaatsField.setText(ex.getMessage());  
                }
                
                //START LIDMAATSCHAP
                try{
                    thisMember.setStartLidmaatschap(PersonLid.convertToDate(startLidmaatschapField.getText()));
                    
                } catch (Exception ex) {
                    
                    validationPassed= false;           
                    errorStartdatumField.setText(ex.getMessage());  
                }
                
                //EIND LIDMAATSCHAP
                try{
                    thisMember.setEindLidmaatschap(PersonLid.convertToDate(eindLidmaatschapField.getText()));
                    
                } catch (Exception ex) {
                    
                    validationPassed= false;          
                    errorEinddatumField.setText(ex.getMessage());  
                }
            
               //call save method and show messages if its OK or NOT
                if(validationPassed){
                    
                    thisMember.save();
                    
                                       
                    
                } else {
                    
                    thisMember.setCode(0);
                    JOptionPane.showMessageDialog(null, "Lid toevoegen niet succesvol. ", "error ", JOptionPane.ERROR_MESSAGE);
                  
                }
           
    }//GEN-LAST:event_lidToevoegenButtonActionPerformed

    private void postcodeFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_postcodeFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_postcodeFieldActionPerformed

    private void startLidmaatschapFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startLidmaatschapFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_startLidmaatschapFieldActionPerformed

    private void ledenReportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ledenReportButtonActionPerformed
        
        new LedenOverzicht().setVisible(true);
        this.dispose();
        
        
    }//GEN-LAST:event_ledenReportButtonActionPerformed

    private void kindButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_kindButtonActionPerformed
        
        if(thisMember.getCode()>0){
            
            new Kindscherm(thisMember.getCode()).setVisible(true);
            
        } else{
            
            JOptionPane.showMessageDialog(null, "Geen geldig lid geselecteerd.", "error", JOptionPane.ERROR_MESSAGE);
            
        }
        
    }//GEN-LAST:event_kindButtonActionPerformed

    private void annulerenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_annulerenButtonActionPerformed
        //check if there is something in the fields already
        boolean fieldsAreNotEmpty = false;
        
        // reset any error messages anyway
        errorNaamField.setText("");
        errorStraatField.setText("");
        errorHuisnummerField.setText("");
        errorPostcodeField.setText("");
        errorGeslachtField.setText("");
        errorEmailField.setText("");
        errorTelefoonField.setText("");
        errorPlaatsField.setText("");
        errorStartdatumField.setText("");
        errorEinddatumField.setText("");      
        
        
        // set a flag whenever that checks wether all JTextFields are empty for when a user presses the cancel button.
        if (!naamField.getText().isEmpty()||
            !straatField.getText().isEmpty()||
            !huisnummerField.getText().isEmpty()||
            !postcodeField.getText().isEmpty()||
            !geslachtCombo.getSelectedItem().equals("kies")||
            !emailField.getText().isEmpty()||
            !telefoonField.getText().isEmpty()||
            !plaatsField.getText().isEmpty()||
            !startLidmaatschapField.getText().isEmpty()||
            !eindLidmaatschapField.getText().isEmpty()) {
            fieldsAreNotEmpty = true;
        }
        
        
        if (fieldsAreNotEmpty) {
            // check if the user really wants to diregard the data in the GUI
            int antwoord = JOptionPane.showConfirmDialog(null, "Wil je deze actie echt annuleren?\n", "verwijder gegevens",
                           JOptionPane.YES_NO_OPTION);  
            
                if (antwoord == JOptionPane.YES_OPTION) {
                    
                    //Set the code to zero so that no Object.member can be passed for kindToeveoegen.
                    try {
                        
                        thisMember.setCode(0);
                        
                    } catch (Exception ex){
                        
                        Logger.getLogger(LedenBeheer.class.getName()).log(Level.SEVERE, null, ex);
                        
                    }
                    
                    //reset all fields and put the code to "next code" as if to start the new member insertion
                    codeField.setText(Integer.toString((PersonLid.getNextCode())));
                    naamField.setText("");
                    straatField.setText("");
                    huisnummerField.setText("");
                    postcodeField.setText("");
                    geslachtCombo.setSelectedIndex(0);
                    emailField.setText("");
                    telefoonField.setText("");
                    plaatsField.setText("");
                    // Show provisional date (current date)
                    startLidmaatschapField.setText(thisMember.getCurrentDate());
                    // Show provisional end date
                    eindLidmaatschapField.setText(thisMember.getCurrentDatePlusYear());
                    
                } else {
                    
                    //window is closed (only for the log, no message to the user is needed)
                    System.out.println("gegevens reset gecancelled ");
                }
            
        } 
        
    }//GEN-LAST:event_annulerenButtonActionPerformed

    private void sluitenButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sluitenButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_sluitenButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(LedenBeheer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(LedenBeheer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(LedenBeheer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(LedenBeheer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new LedenBeheer().setVisible(true);
                
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton annulerenButton;
    private javax.swing.JTextField codeField;
    private javax.swing.JLabel codeLabel;
    private javax.swing.JTextField eindLidmaatschapField;
    private javax.swing.JTextField emailField;
    private javax.swing.JLabel emailLabel;
    private javax.swing.JLabel errorEinddatumField;
    private javax.swing.JLabel errorEmailField;
    private javax.swing.JLabel errorGeslachtField;
    public static javax.swing.JLabel errorHuisnummerField;
    private javax.swing.JLabel errorNaamField;
    private javax.swing.JLabel errorPlaatsField;
    private javax.swing.JLabel errorPostcodeField;
    private javax.swing.JLabel errorStartdatumField;
    private javax.swing.JLabel errorStraatField;
    private javax.swing.JLabel errorTelefoonField;
    private javax.swing.JComboBox geslachtCombo;
    private javax.swing.JLabel geslachtLabel;
    private javax.swing.JTextField huisnummerField;
    private javax.swing.JLabel huisnummerLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JButton kindButton;
    private javax.swing.JLabel kindToeveogenLabel;
    private javax.swing.JButton ledenReportButton;
    private javax.swing.JButton lidToevoegenButton;
    private javax.swing.JTextField naamField;
    private javax.swing.JLabel naamLabel;
    private javax.swing.JTextField plaatsField;
    private javax.swing.JLabel plaatsLabel;
    private javax.swing.JTextField postcodeField;
    private javax.swing.JLabel postcodeLabel;
    private javax.swing.JButton sluitenButton;
    private javax.swing.JTextField startLidmaatschapField;
    private javax.swing.JLabel startLidmaatschapLabel;
    private javax.swing.JTextField straatField;
    private javax.swing.JLabel straatLabel;
    private javax.swing.JTextField telefoonField;
    private javax.swing.JButton zoekButton;
    // End of variables declaration//GEN-END:variables

}
